var myChart = echarts.init(document.getElementById('echats_pressure'));

window.onresize = myChart.resize;
var _testerId = null;
var _tenantId = null;
var _productId = null;
var _boxId = null;
var _flag = null;

function getDeviceParameter(testerId, tenantId, productId, boxId, flag) {
    _testerId = testerId;
    _tenantId = tenantId;
    _productId = productId;
    _boxId = boxId;
    _flag = flag;
    getDeviceByPosition(tenantId, boxId);
    if (_flag == 0) {//正常测试
        getTesterByDevice(testerId, tenantId, productId, boxId);
    } else {//压力测试
        getTesterByPressure(testerId, tenantId, productId, boxId);
    }
    getRealTimeWorking(tenantId, boxId);
}
getDeviceParameter(1,1,1,1,0);
function getTesterByPressure(testerId, tenantId, productId, boxId) {
    $.ajax({
        type: "get",
        url: common.getTesterByPressure,
        data: {
            "testerId": testerId,
            "tenantId": tenantId,
            "productId": productId,
            "boxId": boxId
        },
        success: function (result) {
            //这里是解析的json数据   直接返回data
            var resultDate = result;
            var data = resultDate.data;
            var list = data.reasons;
            var successAllCount = parseInt(data.upSuccess) + parseInt(data.downSuccess);
            var echatsArray = [];
            if (resultDate.code == 0) {
                $('#getTesterByPressure').show();
                $('#boxId').text(data.boxId);//设备编码
                $('#upSuccess').text(data.upSuccess);//上报成功次数
                $('#upFail').text(data.upFail);//上报失败次数
                $('#downSuccess').text(data.downSuccess);//下发成功次数
                $('#downFail').text(data.downFail);//下发失败次数
                $('#alreadyTime').text(data.alreadyTime);//已进行时间
                //转换成map用的json格式
                for (var i = 0; i < list.length; i++) {
                    var _o = {};
                    _o.name = list[i].content + ":" + list[i].number;
                    _o.value = parseInt(list[i].number);
                    echatsArray.push(_o);
                }
                echatsArray.push({"name": "成功次数:" + successAllCount, "value": successAllCount});
                getTesterByPressureForEchats(echatsArray);
            } else {
                common.showMsgTips(resultDate.msg);
            }
        }
    });
}


function getTesterByPressureForEchats(bean) {
    option = {
        title: {
            text: '某站点用户访问来源',
            subtext: '纯属虚构',
            x: 'center'
        },
        tooltip: {
            trigger: 'item',
            formatter: "{a} <br/>{b} : {c} ({d}%)"
        },
        series: [
            {
                name: '访问来源',
                type: 'pie',
                radius: '55%',
                center: ['50%', '60%'],
                data: bean,
                itemStyle: {
                    emphasis: {
                        shadowBlur: 10,
                        shadowOffsetX: 0,
                        shadowColor: 'rgba(0, 0, 0, 0.5)'
                    }
                }
            }
        ]
    };
// 使用刚指定的配置项和数据显示图表。
    myChart.setOption(option);
}

function getTesterByDevice(testerId, tenantId, productId, boxId) {
    /*{"testerId":testerId,
    "tenantId":tenantId,
    "productId":productId,
    "boxId":boxId}*/
    $.ajax({
        type: "get",
        url: common.getTesterByDevice,
        data: {
            "testerId": testerId,
            "tenantId": tenantId,
            "productId": productId,
            "boxId": boxId
        },
        success: function (result) {
            //这里是解析的json数据   直接返回data
            var resultDate = result;
            var data = resultDate.data;
            var list = data.states;
            if (resultDate.code == 0) {
                $('#getTesterByDevice').show();
                $('#boxId').text(data.boxId);//设备编码
                // $('#upSuccess').text(data.upSuccess);//上报成功次数
                // $('#upFail').text(data.upFail);//上报失败次数
                $('#downSuccess').text(data.downSuccess);//下发成功次数
                $('#downFail').text(data.downFail);//下发失败次数
                // $('#alreadyTime').text(data.alreadyTime);//已进行时间
                //转换成map用的json格式
                for (var i = 0; i < list.length; i++) {
                    if (list[i].stateCode == 1003) {//成功
                        $('#upSuccess').text(1);
                        $('#upFail').text(0);//上报失败次数
                    } else {
                        $('#upSuccess').text(0);
                        $('#upFail').text(1);//上报失败次数
                    }
                }

            } else {
                common.showMsgTips(resultDate.msg);
            }
        }
    });
}


// getTesterByPressure(1, 1, 1, 1);
// getTesterByDevice(1, 1, 1, 1);